﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Forms.Core;
using System.Web.UI.WebControls;

namespace ContourStrikesAgain.FieldTypes
{
    public class ReCaptcha : FieldType
    {
        public Recaptcha.RecaptchaControl recaptcha;
        public List<Object> _value;

        public ReCaptcha()
        {
            this.Id = new Guid("77AE810F-2095-4636-9A1F-A719583CE85B");
            this.Name = "ReCaptcha";
            this.Description = "Renders a ReCaptcha";

            //FieldType

            this.Icon = "textfield.png"; //needs to be in the \umbraco\plugins\umbracoContour\images\fieldtypes directory
            this.DataType = FieldDataType.String;

            recaptcha = new Recaptcha.RecaptchaControl();
            _value = new List<object>();
        }

        public override WebControl Editor
        {
            get
            {
                recaptcha.PrivateKey = "6LfmPQkAAAAAAEJxIf-4s7zFPGuytH8Nr5tqxxlU";
                recaptcha.PublicKey = "6LfmPQkAAAAAANZnJSoO-x8zRbFebVuSBJV6Z_c4";
                return recaptcha;
            }
            set
            {
                base.Editor = value;
            }
        }


        public override List<Object> Values
        {
            get
            {
                _value.Clear();
                _value.Add(string.Empty);
                return _value;
            }
            set
            {
                _value = value;
            }
        }

        public override string RenderPreview()
        {

            string imageurl =
                new System.Web.UI.Page().ClientScript.GetWebResourceUrl(this.GetType(), "ContourStrikesAgain.Resources.Images.recaptcha-example.gif");

            return string.Format("<img src=\"{0}\" alt=\"recaptcha\" />",imageurl);
        }

        public override string RenderPreviewWithPrevalues(List<object> prevalues)
        {
            return RenderPreview();
        }


        public override bool SupportsRegex
        {
            get
            {
                return false;
            }
        }

        public override bool SupportsPrevalues
        {
            get
            {
                return false;
            }

        }
    }
}